widget: Don't set widget path on style context
authorBenjamin Otte <otte@redhat.com>
Mon, 19 Mar 2012 00:19:59 +0000 (01:19 +0100)
committerBenjamin Otte <otte@redhat.com>
Tue, 17 Apr 2012 06:59:09 +0000 (08:59 +0200)
Instead, make the style context use the widget's path. Saves a bunch of
memory.

gtk/gtkstylecontext.c
gtk/gtkwidget.c

index 8192a34a6dfd3df89d34b350703db98cf30e60cc..4e8e2827a3d27894ae0cf6be0ddaefbd5c2d10e4 100644 (file)
@@ -922,7 +922,7 @@ create_query_path (GtkStyleContext *context)
   guint i, pos;
 
   priv = context->priv;
-  path = gtk_widget_path_copy (priv->widget_path);
+  path = gtk_widget_path_copy (priv->widget ? gtk_widget_get_path (priv->widget) : priv->widget_path);
   pos = gtk_widget_path_length (path) - 1;
 
   info = priv->info_stack->data;
@@ -967,7 +967,7 @@ style_data_lookup (GtkStyleContext *context,
   if (priv->current_data && priv->current_state == state)
     return priv->current_data;
 
-  g_assert (priv->widget_path != NULL);
+  g_assert (priv->widget != NULL || priv->widget_path != NULL);
 
   if (G_UNLIKELY (state_mismatch))
     {
@@ -982,13 +982,13 @@ style_data_lookup (GtkStyleContext *context,
     {
       GtkWidgetPath *path;
 
+      path = create_query_path (context);
+
       priv->current_data = style_data_new ();
       g_hash_table_insert (priv->style_data,
                            style_info_copy (priv->info_stack->data),
                            priv->current_data);
 
-      path = create_query_path (context);
-
       build_properties (context, priv->current_data, path, state);
 
       gtk_widget_path_free (path);
@@ -1239,7 +1239,7 @@ gtk_style_context_get_section (GtkStyleContext *context,
   g_return_val_if_fail (property != NULL, NULL);
 
   priv = context->priv;
-  g_return_val_if_fail (priv->widget_path != NULL, NULL);
+  g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
 
   prop = _gtk_style_property_lookup (property);
   if (!GTK_IS_CSS_STYLE_PROPERTY (prop))
@@ -1286,7 +1286,7 @@ gtk_style_context_get_property (GtkStyleContext *context,
   g_return_if_fail (value != NULL);
 
   priv = context->priv;
-  g_return_if_fail (priv->widget_path != NULL);
+  g_return_if_fail (priv->widget != NULL || priv->widget_path != NULL);
 
   prop = _gtk_style_property_lookup (property);
   if (prop == NULL)
@@ -1544,7 +1544,10 @@ gtk_style_context_get_path (GtkStyleContext *context)
   GtkStyleContextPrivate *priv;
 
   priv = context->priv;
-  return priv->widget_path;
+  if (priv->widget)
+    return gtk_widget_get_path (priv->widget);
+  else
+    return priv->widget_path;
 }
 
 /**
@@ -2240,8 +2243,9 @@ _gtk_style_context_peek_style_property (GtkStyleContext *context,
   if (priv->widget || priv->widget_path)
     {
       if (gtk_style_provider_get_style_property (GTK_STYLE_PROVIDER (priv->cascade),
-                                                 priv->widget_path, state,
-                                                 pspec, &pcache->value))
+                                                 priv->widget ? gtk_widget_get_path (priv->widget)
+                                                              : priv->widget_path,
+                                                 state, pspec, &pcache->value))
         {
           /* Resolve symbolic colors to GdkColor/GdkRGBA */
           if (G_VALUE_TYPE (&pcache->value) == GTK_TYPE_SYMBOLIC_COLOR)
@@ -2318,17 +2322,24 @@ gtk_style_context_get_style_property (GtkStyleContext *context,
 
   priv = context->priv;
 
-  if (!priv->widget_path)
-    return;
+  if (priv->widget)
+    {
+      widget_type = G_OBJECT_TYPE (priv->widget);
+    }
+  else
+    {
+      if (!priv->widget_path)
+        return;
 
-  widget_type = gtk_widget_path_get_object_type (priv->widget_path);
+      widget_type = gtk_widget_path_get_object_type (priv->widget_path);
 
-  if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
-    {
-      g_warning ("%s: can't get style properties for non-widget class `%s'",
-                 G_STRLOC,
-                 g_type_name (widget_type));
-      return;
+      if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
+        {
+          g_warning ("%s: can't get style properties for non-widget class `%s'",
+                     G_STRLOC,
+                     g_type_name (widget_type));
+          return;
+        }
     }
 
   widget_class = g_type_class_ref (widget_type);
@@ -2383,17 +2394,24 @@ gtk_style_context_get_style_valist (GtkStyleContext *context,
   prop_name = va_arg (args, const gchar *);
   priv = context->priv;
 
-  if (!priv->widget_path)
-    return;
+  if (priv->widget)
+    {
+      widget_type = G_OBJECT_TYPE (priv->widget);
+    }
+  else
+    {
+      if (!priv->widget_path)
+        return;
 
-  widget_type = gtk_widget_path_get_object_type (priv->widget_path);
+      widget_type = gtk_widget_path_get_object_type (priv->widget_path);
 
-  if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
-    {
-      g_warning ("%s: can't get style properties for non-widget class `%s'",
-                 G_STRLOC,
-                 g_type_name (widget_type));
-      return;
+      if (!g_type_is_a (widget_type, GTK_TYPE_WIDGET))
+        {
+          g_warning ("%s: can't get style properties for non-widget class `%s'",
+                     G_STRLOC,
+                     g_type_name (widget_type));
+          return;
+        }
     }
 
   state = gtk_style_context_get_state (context);
@@ -2481,7 +2499,7 @@ gtk_style_context_lookup_icon_set (GtkStyleContext *context,
   g_return_val_if_fail (stock_id != NULL, NULL);
 
   priv = context->priv;
-  g_return_val_if_fail (priv->widget_path != NULL, NULL);
+  g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
 
   return gtk_icon_factory_lookup_default (stock_id);
 }
@@ -2799,7 +2817,7 @@ gtk_style_context_notify_state_change (GtkStyleContext *context,
   g_return_if_fail (state > GTK_STATE_NORMAL && state <= GTK_STATE_FOCUSED);
 
   priv = context->priv;
-  g_return_if_fail (priv->widget_path != NULL);
+  g_return_if_fail (priv->widget != NULL || priv->widget_path != NULL);
 
   state_value = (state_value == TRUE);
 
@@ -3476,7 +3494,7 @@ gtk_style_context_get_font (GtkStyleContext *context,
   g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
 
   priv = context->priv;
-  g_return_val_if_fail (priv->widget_path != NULL, NULL);
+  g_return_val_if_fail (priv->widget != NULL || priv->widget_path != NULL, NULL);
 
   data = style_data_lookup (context, state);
 
index 1abd81491ecc0e5307745a25778837d4f694bf70..ab5071b22e26aecf1ec27f748b62f8e7b121835e 100644 (file)
@@ -14065,8 +14065,7 @@ gtk_widget_get_path (GtkWidget *widget)
         }
 
       if (widget->priv->context)
-        gtk_style_context_set_path (widget->priv->context,
-                                    widget->priv->path);
+        gtk_style_context_invalidate (widget->priv->context);
     }
 
   return widget->priv->path;
@@ -14102,15 +14101,11 @@ GtkStyleContext *
 gtk_widget_get_style_context (GtkWidget *widget)
 {
   GtkWidgetPrivate *priv;
-  GtkWidgetPath *path;
 
   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
 
   priv = widget->priv;
   
-  /* updates style context if it exists already */
-  path = gtk_widget_get_path (widget);
-
   if (G_UNLIKELY (priv->context == NULL))
     {
       GdkScreen *screen;
@@ -14123,7 +14118,6 @@ gtk_widget_get_style_context (GtkWidget *widget)
       if (screen)
         gtk_style_context_set_screen (priv->context, screen);
 
-      gtk_style_context_set_path (priv->context, path);
       if (priv->parent)
         gtk_style_context_set_parent (priv->context,
                                       gtk_widget_get_style_context (priv->parent));